package com.ts.main.mini.controller;

import com.ts.main.mini.dto.ShoppingCartDto;
import com.ts.main.mini.dto.ShoppingCartPageSearchDto;
import com.ts.main.mini.exception.R;
import com.ts.main.mini.exception.RPage;
import com.ts.main.mini.service.ShoppingCartServiceImpl;
import com.ts.main.mini.vo.ShoppingCartVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 小程序-购物车管理
 * @Author:lk
 * @Date: 2025/5/18  17:22
 */
@AllArgsConstructor
@RestController
@RequestMapping("/mini/shopping")
@Tag(name = "小程序-购物车管理")
public class ShoppingCartController {
    
    private final ShoppingCartServiceImpl shoppingCartService;


    /**
     * 查询购物车列表（分页查询）
     * @return
     */
    @Operation(summary = "查询购物车列表（分页查询）")
    @PostMapping("/getCartPage")
    public RPage<List<ShoppingCartVo>> getCartPage(@RequestBody ShoppingCartPageSearchDto dto){
        return shoppingCartService.getCartPage(dto);
    }

    /**
     * 查询购物车列表
     * @return
     */
    @Operation(summary = "查询购物车列表")
    @GetMapping("/getCartList")
    public R<List<ShoppingCartVo>> getCartList(){
        return R.ok(shoppingCartService.getCartList());
    }

    /**
     * 查询购物车详情
     * @return
     */
    @Operation(summary = "查询购物车详情")
    @GetMapping("/getCartDetails")
    public R<ShoppingCartVo> getCartDetails(@Schema(description = "购物车ID") @RequestParam("cartId") Integer cartId){
        return R.ok(shoppingCartService.getCartDetails(cartId));
    }

    /**
     * 添加购物车
     */
    @Operation(summary = "添加购物车")
    @PostMapping("/saveCart")
    public R<Boolean> saveCart(@RequestBody ShoppingCartDto dto){
        return R.ok(shoppingCartService.saveCart(dto));
    }

    /**
     * 修改购物车
     */
    @Operation(summary = "修改购物车")
    @PutMapping("/updateCart")
    public R<Boolean> updateCart(@RequestBody ShoppingCartDto dto){
        return R.ok(shoppingCartService.updateCart(dto));
    }

    /**
     * 删除购物车
     */
    @Operation(summary = "删除购物车")
    @DeleteMapping("/deleteCart")
    public R<Boolean> deleteCart(@Schema(description = "购物车ID集合") @RequestParam("ids") List<Integer> ids){
        return R.ok(shoppingCartService.deleteCart(ids));
    }

}
